package com.itheima;

import com.itheima.pojo.Category;
import com.itheima.pojo.Employee;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.R;
import com.itheima.service.CategoryService;
import com.itheima.service.EmpService;
import com.itheima.service.UserService;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class Demo {
    @Autowired
    private UserService userService;
    @Autowired
    private EmpService empService;
    @Autowired
    private CategoryService categoryService;

    @Test
    public void findByPhone(){
        boolean b = userService.findByPhone("13820919076");
        System.out.println(b);
    }

    @Test
    public void findAll(){
        List<Employee> all = empService.findAll(1, 10);
        System.out.println(all);
    }

    @Test
    public void findByLikeName(){
        List<Employee> list = empService.findByLikeName(1, 10, "张");
        System.out.println(list);
    }


    @Test
    public void selectCount(){
        Integer integer = empService.selectCount();
        System.out.println(integer);
    }

    @Test
    public void login(){
        Employee employee = new Employee();
        employee.setUsername("zhangsan");
        employee.setPassword("123456");
        Employee employeeResult = empService.login(employee);
        System.out.println(employeeResult);
    }


    @Test
    public void addEmpService(){
        Employee employee = new Employee();
        employee.setUsername("qianqi");
        employee.setName("钱七");
        employee.setPassword("123456");
        employee.setPhone("13012341234");
        employee.setSex("男");
        employee.setIdNumber("342401199900000801");
        employee.setStatus(1);
        employee.setCreateTime(new Date());
        employee.setCreateUser(1L);
        employee.setUpdateUser(1L);
        employee.setUpdateTime(new Date());

        boolean b = empService.add(employee);
        System.out.println(b);
    }

    @Test
    public void addCategoryService(){
        Category category = new Category();
        category.setSort(100);
        category.setName("东北菜");
        category.setType(1);

        R r = categoryService.add(category);
        System.out.println(r);
    }

    @Test
    public void findPage(){
        R<PageResult> page = categoryService.findPage(1, 10);
        System.out.println(page);
    }


    @Test
    public void removeById(){
        R r = categoryService.removeById(1);
        System.out.println(r);
    }

    @Test
    public void modify(){
        Category category = new Category();
        category.setName("凉菜");
        category.setSort(111);
        category.setId(11L);
        category.setType(1);
        R r = categoryService.modify(category);
        System.out.println(r);
    }
}
